import { reactive } from "vue";
import { dataMiddleGroundBaseSmsSendCaptchaMsg } from "@/api/data-middleground-base/base/sms";
import { ElMessage } from "element-plus";
import { i18n } from "@/locale";
const useI18n: any = i18n.global;
const t = useI18n.t;
const codeEvent = reactive({
  time: 60,
  flag: false,
  async getCode(obj: object) {
    const res = await dataMiddleGroundBaseSmsSendCaptchaMsg(obj);
    if (res.errno == 0) {
      codeEvent.flag = true;
      codeEvent.timer();
      ElMessage({
        message: t(`responseMsg.codeSuccess`),
        type: "success",
      });
    }
  },
  timer: () => {
    let a = setInterval(() => {
      codeEvent.time--;
      if (codeEvent.time == 0) {
        codeEvent.flag = false;
        codeEvent.time = 60;
        clearInterval(a);
      }
    }, 1000);
  },
});
export default function verificationCode() {
  return {
    codeEvent,
  };
}
